package com.team.client_server;

public abstract class Message {

	
	MessageHeader messageHeader;
	int id;
	int sequenceNumber;
	String[] param;
	
	
	public Message(String message){
		parseMessage(message);
	}
	
	public Message(MessageHeader em, int id, int seq) {
		this.id = id;
		this.messageHeader = em;
		this.sequenceNumber = seq;
	}
	
	
	public abstract String createMessage();
	protected abstract void parseMessage(String message);
	
	protected String subMessage(String start, String end, int nbChar, String message){
		int startPosition;
		int endPosition;
		
		startPosition = message.indexOf(start);
		endPosition = message.indexOf(end);
		if (startPosition == -1 || endPosition == -1){
			//throw error messageException
		}
		return message.substring(startPosition + nbChar, endPosition);
	}
	
	public MessageHeader getMessageHeader() {
		return messageHeader;
	}

	public void setMessageHeader(MessageHeader em) {
		this.messageHeader = em;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getSequenceNumber() {
		return sequenceNumber;
	}

	public void setSequenceNumber(int seq) {
		this.sequenceNumber = seq;
	}

	public String[] getParam() {
		return param;
	}

	public void setParam(String[] param) {
		this.param = param;
	}

}
